package com.zhangtao.demo.common.config;

import java.io.File;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class GloableConfig {

	@Value("${local.fileserver.dir}")
	private String localResourcePath;
	@Value("${local.fileserver.url}")
	private String fetchFileUrl;

	@PostConstruct
	public void initFileSource() {
		String driveName = this.getLocalDrive();
		String localResourcePathStr = driveName + localResourcePath;
		this.localResourcePath = localResourcePathStr;
		File fileDir = new File(localResourcePathStr);
		if (!fileDir.exists()) {
			fileDir.mkdirs();
		}
	}

	// 获取本地系统盘符
	public String getLocalDrive() {
		File[] files = File.listRoots();
		for(int i = 0; i < files.length; i++) {
			if (!files[i].toString().startsWith("C:")) {
				return files[i].toString();
			}
		}
		return null;
	}
	public String getLocalResourcePath() {
		return localResourcePath;
	}

	public String getRemoteFileUrl() {
		return fetchFileUrl;
	}
}
